<?php
namespace app\index\controller;
use think\Controller;
use think\Collection;
use think\Db;
use \Page;
class Map extends CommonController{
	public function map($id){
		$data=Db::table('hall')->where("id",$id)->select();
		$json=Db::table('map_count')->field('lng,lat,count')->select();
		$point=json_encode($json);
		$this->assign('point',$point);
		// var_dump($point);
		// var_dump($a);
		// var_dump($data);
		$this->assign([
            'lon' => $data[0]['longitude'],
            'lat' => $data[0]['latitude'],
            'place'=>$data[0]['name']
            ]);
		// $this->assign('name',$name);
		return $this->fetch('gomap/map');
	}
	public function map_sking($id)
	{
		$data=Db::table('sking')->where("id",$id)->select();
		$json=Db::table('map_count')->field('lng,lat,count')->select();
		$point=json_encode($json);
		$this->assign('point',$point);
		// var_dump($point);
		// var_dump($a);
		// var_dump($data);
		$this->assign([
            'lon' => $data[0]['lng'],
            'lat' => $data[0]['lat'],
            'place'=>$data[0]['place']
            ]);
		// $this->assign('name',$name);
		return $this->fetch('gomap/map');
	}
	//北京赛区12
	public function partition(){
		$data=Db::table('hall')->where("class",1)->select();
		// var_dump($data);
		$p = new Page($data,20);
		$this->assign('list',$p);
		return $this->fetch('gomap/partition');
	}
	//张家口赛区8
	public function zhang_zone(){
		$data=Db::table('hall')->where("class",3)->select();
		// var_dump($data);
		$p = new Page($data,20);
		$this->assign('list',$p);
		return $this->fetch('gomap/zhang_zone');
	}
	//延庆赛区5
	public function yanqing_zone(){
		$data=Db::table('hall')->where("class",2)->select();
		// var_dump($data);
		$p = new Page($data,20);
		$this->assign('list',$p);
		return $this->fetch('gomap/yanqing_zone');
	}
	//滑雪推荐
	public function sking($class){
		$data_1 = Db::table('sking')->where('class',$class)->select();
		// $data_2 = Db::table('sking')->where('class',2)->select();
		// $data_3 = Db::table('sking')->where('class',3)->select();
		$p_1 = new Page($data_1,20);
		// $p_2 = new Page($data_2,20);
		// $p_3 = new Page($data_3,20);
		$this->assign(['list_1'=>$p_1]);
		// var_dump($data_3);
		return $this->fetch('gomap/sking');
	}
	//特色小吃
	public function snack(){
		return $this->fetch('gomap/snack');
	}

	public function point_post($lat,$lng){
		$number=getCookie();
		$db=Db::table('map_point');
		$data=$db->where('number',$number)->select();
		$lat_1=mb_substr($lat,0,7,'utf-8');//map_count的字段
		$lng_1=mb_substr($lng,0,8,'utf-8');//map_count的字段
		$data_1=Db::table('map_count')->where(['lat'=>$lat_1,'lng'=>$lng_1])->select();
		$count=Db::table('map_count')->field('count')->where(['lat'=>$lat_1,'lng'=>$lng_1])->select();
		//return $lat;
		if ($data!=null) {
			// var_dump(0);
			$sql=Db::table('map_point')->where('number',$number)->update(['lat'=>$lat,'lng'=>$lng]);
		}
		else{
			$sql_1=Db::table('map_point')->insert(['number'=>$number,'lat'=>$lat,'lng'=>$lng]);//+++
			
			if ($data_1!=null) {
				// var_dump(2);
				 $a =$count[0]['count'] +1;
				$sql_2=Db::table('map_count')->where(['lat'=>$lat_1,'lng'=>$lng_1])->update(['count'=>$a]);				
			}
			else
			{
				// var_dump(1);
				$count=1;
				$sql_2=Db::table('map_count')->insert(['count'=>$count,'lat'=>$lat_1,'lng'=>$lng_1]);
			}
		}
		// return dump($data);
	}
}